<template>
  <div>
    <!-- 标签 -->
    <div class="photo-title-warp" v-if="!$common.isEmpty(photoTitleList)">
      <div
        v-for="(item, index) in photoTitleList"
        :key="index"
        :class="{
          isActive: photoPagination.classify === item.classify,
        }"
        @click="changePhotoTitle(item.classify)"
      >
        <proTag
          :info="item.classify + ' ' + item.count"
          :color="$constant.before_color_list[Math.floor(Math.random() * 6)]"
          style="margin: 12px"
        >
        </proTag>
      </div>
    </div>

    <div class="photo-title">
      {{ photoPagination.classify }}
    </div>

    <photo :resourcePathList="photoList"></photo>
    <div class="pagination-wrap">
      <div
        @click="pagePhotos()"
        class="pagination"
        v-if="photoPagination.total !== photoList.length"
      >
        下一页
      </div>
      <div v-else style="user-select: none">~~到底啦~~</div>
    </div>
  </div>
</template>

<script>
import photo from "../travel/photo.vue"
export default {
  components: {
    photo
  },
  data() {
    return {
      photoTitleList: [],
      photoPagination: {
        current: 1,
        size: 10,
        total: 0,
        resourceType: "lovePhoto",
        classify: "",
      },
      photoList: [],
    };
  },
  methods: {
    pagePhotos() {
      this.photoPagination.current = this.photoPagination.current + 1;
      this.changePhoto();
    },
    changePhoto() {
      this.$createHttp
        .listResourcePath(this.photoPagination)
        .then((res) => {
          if (!this.$common.isEmpty(res.data)) {
            this.photoList = this.photoList.concat(res.data.records);
            this.photoPagination.total = res.data.total;
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: "error",
          });
        });
    },
    getPhotoTitles() {
      this.$createHttp
        .listAdminLovePhoto()
        .then((res) => {
          if (!this.$common.isEmpty(res.data)) {
            this.photoTitleList = res.data;
            this.photoPagination = {
              current: 1,
              size: 10,
              total: 0,
              resourceType: "lovePhoto",
              classify: this.photoTitleList[0].classify,
            };
            this.changePhoto();
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: "error",
          });
        });
    },
  },
};
</script>

<style scoped>
.photo-title {
  text-align: center;
  font-size: 30px;
  font-weight: 700;
  line-height: 80px;
  letter-spacing: 2px;
}

.photo-title-warp {
  max-width: 1150px;
  margin: 50px auto;
  padding: 20px;
  border-radius: 10px;
  display: flex;
  flex-wrap: wrap;
}

.pagination-wrap {
  display: flex;
  justify-content: center;
  margin-top: 40px;
}

.pagination {
  padding: 13px 15px;
  border: 1px solid var(--lightGray);
  border-radius: 3rem;
  color: var(--greyFont);
  width: 100px;
  user-select: none;
  cursor: pointer;
  text-align: center;
}

.pagination:hover {
  border: 1px solid var(--themeBackground);
  color: var(--themeBackground);
  box-shadow: 0 0 5px var(--themeBackground);
}
</style>
